package com.github.live.util;

import com.github.live.base.GloabConfig;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @ClassName ExecutorServiceUtil
 * @description:
 * @author: biao532
 * @create: 2023-12-22 17:31
 * @Version 1.0
 **/
public class ExecutorServiceUtil {
    private static ExecutorService service;
    public static void init(int size) {
        if (size > 0) {
            service = Executors.newFixedThreadPool(size);
        }
    }
    public static Future<?> submit(Runnable runnable) {
        if (service == null) {
            runnable.run();
            return new FutureTask<>(() -> {
                runnable.run();
                return null;
            });
        }
        return service.submit(runnable);
    }
}
